import os
import platform
import sys

# Read command arguments,
mode = ARGUMENTS.get("mode", "release")

if not (mode in ["debug", "release", "profile", "pedantic"]):
	print "Invalid build mode '%s'." % mode
	Exit(1)

print "**** Compiling in " + mode + " mode..."

ccflags = {
	"profile" : "-g -pg -Wall -Weffc++",
	"pedantic" : "-g -Wall -Weffc++ -std=c++0x",
	"debug" : "-g -Wall -std=c++0x",
	"release" : "-O3 -Wall -std=c++0x"
}
linkflags = {
	"profile" : "-pg " + os.environ['LDLIBS'],
	"pedantic" : "" + os.environ['LDLIBS'],
	"debug" : "" + os.environ['LDLIBS'],
	"release" : "" + os.environ['LDLIBS']
}
if sys.platform.startswith('linux'):
	defines = {
		"profile" : "_REENTRANT _THREADSAFE DEBUG LINUX",
		"pedantic" : "_REENTRANT _THREADSAFE DEBUG LINUX",
		"debug" : "_REENTRANT _THREADSAFE DEBUG LINUX",
		"release" : "_REENTRANT _THREADSAFE NDEBUG RELEASE LINUX"
	}
	libs = ["rt", "trng4"]

if sys.platform.startswith('win32'):
	defines = {
		"profile" : "_REENTRANT _THREADSAFE DEBUG WINDOWS",
		"pedantic" : "_REENTRANT _THREADSAFE DEBUG WINDOWS",
		"debug" : "_REENTRANT _THREADSAFE DEBUG WINDOWS",
		"release" : "_REENTRANT _THREADSAFE NDEBUG RELEASE WINDOWS"
	}
	libs = []

env = Environment(CPPPATH = ['./includes', os.environ['CPP_INCLUDE']])
env.VariantDir('build', '.', duplicate = 0)
env.Append(CCFLAGS = ccflags[mode].split(" "))
env.Append(LINKFLAGS = linkflags[mode].split(" "))
env.Append(CPPDEFINES = defines[mode].split(" "))


env.Program(
	'random-%s' % platform.machine(),
	Glob('build/*.cpp'),
	LIBS=libs
)



